package com.gsm.controller;

import com.gsm.entity.Subject;
import com.gsm.service.SubjectService;
import com.gsm.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 科目(Subject)表控制层
 *
 * @author wjq
 * @since 2020-04-26 22:59:08
 */
@RestController
@RequestMapping("subject")
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    /**
     * 新增
     */
    @PostMapping("subject")
    public Result insertSubject(@RequestBody Subject subject) {
        Result result = subjectService.insertSubject(subject);
        return result;
    }

    /**
     * 根据 id 删除数据
     */
    @DeleteMapping("subject/{subjectId}")
    public Result deleteSubjectBySubjectId(@PathVariable("subjectId") Long subjectId) {
        Result result = subjectService.deleteSubjectBySubjectId(subjectId);
        return result;
    }

    /**
     * 根据 id 修改单条数据
     */
    @PutMapping("subject/{subjectId}")
    public Result updateSubjectBySubjectId(@PathVariable("subjectId") Long subjectId, @RequestBody Subject subject) {
        subject.setSubjectId(subjectId);
        Result result = subjectService.updateSubjectBySubjectId(subject);
        return result;
    }

    /**
     * 根据 id 修改课程和课程详细单条数据
     */
    @PutMapping("subjectAndDetails/{subjectId}")
    public Result updateSubjectAndDetailsBySubjectId(@PathVariable("subjectId") Long subjectId, @RequestBody Subject subject) {
        subject.setSubjectId(subjectId);
        Result result = subjectService.updateSubjectAndDetailsBySubjectId(subject);
        return result;
    }

    /**
     * 批量修改 课程
     */
    @PutMapping("subjects")
    public Result updateSubjects(@RequestBody List<Subject> subjects) {
        Result result = subjectService.updateSubjects(subjects);
        return result;
    }

    /**
     * 根据 id 查询单条数据
     */
    @GetMapping("subject/{subjectId}")
    public Result selectSubjectBySubjectId(@PathVariable("subjectId") Long subjectId) {
        Result result = subjectService.selectSubjectBySubjectId(subjectId);
        return result;
    }

    /**
     * 根据条件查询 List
     */
    @GetMapping("subjectList")
    public Result selectSubjectList(Subject subject) {
        Result result = subjectService.selectSubjectList(subject);
        return result;
    }
}